<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
     var arr = [3,2,1];
     var sum=0;
     var sumTwo=0;
     var sumThree=0;
     for (var i=0;i<3;i++){
         sum += arr[i] * pow(27,arr.length-1 - i)
     }
     function pow(number,x) {
         var counter = 0;
         if(x ==1){
             return number
         }else if(x == 0){
              return  1;d
         }
         for (var i=0;i<x-1;i++){
              counter += number  * number;
         }
         return counter
     }

     for (var k=0;k<3;k++){
         sumTwo = 27 * sumTwo + arr[k];
     }

     console.log(sum);
     console.log(sumTwo);
</script>
</body>
</html>